#pragma once
#include <sys/epoll.h>
#include <unistd.h>
#include <time.h>
#include <cstdlib>
class Epoll
{
    const static int gnum = 128;
    const static int gtimeout = 5000;

public:
    Epoll(int timeout = gtimeout):_timeout(timeout) {};
    void EpollCreater()
    {
        _efds=epoll_create(gnum);
        if(_efds<0) exit(1);
    }
    bool CtrlEpoll(int sock,uint32_t events)
    {
        events |= EPOLLET;
        struct epoll_event ev;
        ev.events = events;
        ev.data.fd = sock;
        int n=epoll_ctl(_efds,EPOLL_CTL_ADD,sock,&ev);
        return n==0;
    }
    bool AddSockToEpoll(int sock,uint32_t events)
    {
        struct epoll_event ev;
        ev.events = events;
        ev.data.fd = sock;
        int n=epoll_ctl(_efds,EPOLL_CTL_ADD,sock,&ev);
        return n==0;
    }

    int WaitPoll(struct epoll_event revs[], int num)
    {
        return epoll_wait(_efds,revs,num,_timeout);
    }
    

private:
    int _efds;
    int _timeout;
};